package com.ysd.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ysd.entity.Message;
import com.ysd.service.MessageService;
import com.ysd.util.Result;

@Controller
public class MessageController {

	
	@Autowired
	private MessageService messageService;
	
	@RequestMapping("getMessage")
	@ResponseBody
	public String getMessage(Message message) {
		message.setPage((message.getPage()-1)*message.getLimit());
	List<Message>	list=messageService.findMessage(message);
	int	n=messageService.getPage(message);
	if(list!=null) {
		return Result.toClient("0", "查询成功", n, list);
	} else {
		return Result.toClient("1", "查询失败", null, null);
	}
	
	}
	
	@RequestMapping("updateMessage")
	@ResponseBody
	public String updateMessage(Message message) {
	int	n=messageService.updateMessage(message);
		if(n>0) {
			return Result.toClient("0", "修改成功",null);
		}else {
			return Result.toClient("1", "修改失败",null);
		}
	
	
	}
}
